<%@page import="java.util.Date"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<head>
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript">
	function doAjax() {
		$.ajax({
			url : 'time.html',
			data : 
			({ name : "me" }),
			success : function(data) {
				$('.time').html(data);
				$('.btAdd').hide(1000, "swing");
			}
		});
	}
</script>

<script type="text/javascript">
	function addToCart(itemId) {
	    var myurl = "addToCart.html";
	    
	    $.ajax({
	    	url: myurl,
	    	data: ({
	    		id : itemId,
	    	}),
	    	success : function(data) {
	    		$('#bt'+itemId).hide("slow", "swing", function()
	    				{
	    					$('#' + itemId).show();
	    				});
	    		
	    	}
	    });
	}
	
</script>

</head>
<body>
	<div class="content">
		<!--banner-->
		<div class="content-banner">
			<ul class="bxslider">
				<img src="resources/images/banner1.png" />
				<img src="resources/images/banner2.png" />
				<img src="resources/images/banner3.png" />
				<img src="resources/images/banner4.png" />
			</ul>
		</div>
		<!--main content-->
		
		
		<div class="content-main">
		
			<div class="content-main-block">
				<div class="title">
					<p>SẢN PHẨM GIẢM GIÁ</p>
				</div>
				<c:forEach var="detail" items="${productDiscount}">
					<div class="item-main-block">
						<div class="icon">SELL</div>
						<a href="detail.html?id=${detail.productDetailId}"
							style="text-decoration: none"> <img
							src="${detail.image.imageUrl}" />
							<div class="items-details">
								<div class="item-name">${detail.getName()}</div>
								<div class="item-price-old">
									<fmt:formatNumber type="number" maxFractionDigits="0"
										value="${detail.oldPrice}" />
									VND
								</div>
								<div class="item-price">
									<fmt:formatNumber type="number" maxFractionDigits="0"
										value="${detail.price}" />
									VND
								</div>
							</div>
						</a>
						<c:set var="flag" value="${0}"></c:set>
						<c:forEach var="it" items="${cartUser.cartDetails}">
							<c:if test="${it.productDetail.productDetailId == detail.productDetailId && flag != 1}">
								<div>Đã thêm vào giỏ hàng</div>
								<c:set var="flag" value="${1}"></c:set>
							</c:if>
						</c:forEach>
						
						<c:if test="${flag != 1}">
							<button id="bt${detail.productDetailId}" onclick="addToCart(${detail.productDetailId})" title="Thêm vào giỏ hang">Thêm vào giỏ hàng</button>
							<div id="${detail.productDetailId}"  class="hidediv">Đã thêm vào giỏ hàng</div>
						</c:if>

					</div>
					

				</c:forEach>
			</div>

			<a href="terms.html">TEETETET</a>
			<div class="content-main-block">
				<div class="title">
					<p>SẢN PHẨM MỚI</p>
				</div>

				<c:forEach var="detail" items="${productNew}">
					<div class="item-main-block">
						<div class="icon">NEW</div>
						<a href="detail.html?id=${detail.productDetailId}"
							style="text-decoration: none"> <img
							src="${detail.image.imageUrl}" />
							<div class="items-details">
								<div class="item-name">${detail.product.productName}</div>

								<div class="item-price">
									<fmt:formatNumber type="number" maxFractionDigits="0"
										value="${detail.price}" />
									VND
								</div>
							</div>
						</a>
						<c:set var="flag" value="${0}"></c:set>
						<c:forEach var="it" items="${cartUser.cartDetails}">
							<c:if test="${it.productDetail.productDetailId == detail.productDetailId && flag != 1}">
								<div>Đã thêm vào giỏ hàng</div>
								<c:set var="flag" value="${1}"></c:set>
							</c:if>
						</c:forEach>
						
						<c:if test="${flag != 1}">
							<button id="bt${detail.productDetailId}" onclick="addToCart(${detail.productDetailId})" title="Thêm vào giỏ hang">Thêm vào giỏ hàng</button>
							<div id="${detail.productDetailId}"  class="hidediv">Đã thêm vào giỏ hàng</div>
						</c:if>
					</div>
				</c:forEach>
			</div>
		</div>
	</div>
	<!-- CONTENT : START -->

</body>